$(function(){
    //------------------------------------------------------------------------------------------------------------------
    //企业会员手机号码验证
    $.validator.addMethod("checkMobile", function(value, element,param) {
        var phone =  $("#"+param[0]).val() + '-' + $("#"+param[1]).val() + '-' +$("#"+param[2]).val();
        phone =str_trim(phone);
        if( value == '' && phone == ''  ){
            return false;
        }else {
            return true;
        }
    }, "请输入正确的手机号码");

    //企业会员电话号码验证
    $.validator.addMethod("checkPhone", function(value, element,param) {
        var phone =  $("#"+param[0]).val() + '-' + value + '-' +$("#"+param[1]).val();
        phone =str_trim(phone);
        if(phone != ''){
            var regu =/(^[0-9]{2,5}\-[0-9]{7,9})((\-\d{0,10})?)$/g;
            if(regu.test(phone)){
                return true;
            }else{
                return false;
            }
        }else {
            return true;
        }
    }, "请输入正确的区号和电话号码");

    //企业会员传真号码验证
    $.validator.addMethod("checkFax", function(value, element,param) {
        if(value != ''){
            var regu =/(^[0-9]{2,5}\-[0-9]{7,9})$/g;
            if(regu.test(value)){
                return true;
            }else{
                return false;
            }
        }else {
            return true;
        }
    }, "请输入正确的传真号码");

    //企业QQ号码验证
    $.validator.addMethod("checkQQ", function(value, element,param) {
        if(value != ''){
            var regu =/(^[1-9]{1}[0-9]{4,15})$/g;
            if(regu.test(value)){
                return true;
            }else{
                return false;
            }
        }else {
            return true;
        }
    }, "请输入正确的QQ号码");


    //企业会员表单验证 使用jQuery Validate 插件进行验证
    $('#regBasicForm').validate({
        //指定使用什么标签标记错误。
        errorElement: "span",
        //一个函数，可以自定义错误放到哪里。
        errorPlacement: function(error, element) {
            $(element).parents('dl').find(".errinfo").append(error);
        },
        //自定义错误消息
        tipPlacement: function(element,tip) {
            $(element).parents('dl').find(".errinfo").append(tip);
        },
        //通过验证后执行的函数
        success: function(label){
            if(label.parents('dl').find('dd input').val()!=''){
                label.text('ok!').addClass('success');
            }
        },
        //未验证后执行的函数
        highlight: function(element, errorClass) {
            $( element ).closest( "dl" ).find("dd.errinfo").find('span').removeClass('success');
        },
        ignore:"",
        //js上面添加验证规则
        rules: {
            company_name: {
                required: true
            },
            industry: {
                required: true
            },
            established: {
                required: true
            },
            temptation: {
                required: true
            },
            profile: {
                required: true
            },
            contacts: {
                required: true
            },
            mobile: {
                checkMobile:['area_code','phone','ext'] //期望的是true,如果为false则展示提示信息
            },
            phone:{
                checkPhone:['area_code','ext']          //期望的是true,如果为false则展示提示信息
            },
            fax:{
                checkFax:true                          //期望的是true,如果为false则展示提示信息
            },
            email: {
                email: true
            },
            qq: {
                checkQQ:true                            //期望的是true,如果为false则展示提示信息
            },
            region: {
                required: true
            },
            address: {
                required: true
            }
        },
        //错误信息提示修改
        messages: {
            company_name: {
                required: "请输入公司名称"
            },
            industry: {
                required: "请选择所属行业"
            },
            established: {
                required: "请选择成立年份"
            },
            temptation: {
                required: "请选择公司诱惑"
            },
            profile: {
                required: "请输入公司简介"
            },
            contacts: {
                required: "请输入联系人"
            },
            email: {
                email: "请输入一个正确的邮箱"
            },
            region: {
                required: "请选择地区"
            },
            address: {
                required: "请输入详细地址"
            }
        },
        submitHandler:function(form) {
            form.submit();
        }
    });
    //$('form input[placeholder]').placeholder({isUseSpan:true});
});

// ----------------------------------------------------------------------------------------------------------------------------

